package com.example.wx.persistence.DAOImpl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.wx.domain.CompleteCase;
import com.example.wx.domain.SingleBriefCase;
import com.example.wx.persistence.CaseAnalysisDAO;
import com.example.wx.util.DataBaseUtil;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;

@Repository("caseAnalysisDAO")
public class CaseAnalysisDAOImpl implements CaseAnalysisDAO {

    @Override
    public ArrayList<SingleBriefCase> getAllCase() {

        //String request = "{\"env\":\"cloud1-0gmugs6v938df3dc\"," + "\"query\":\"db.collection(\\\"admin_info\\\").where({username:\\\"admin1\\\"}).get()\"}";

        //JSONArray dataArray = DataBaseUtil.action(request).getJSONArray("data");

        // Test
        SingleBriefCase s1 = new SingleBriefCase();
        s1.setCase_id("777");
        s1.setLatitude("7777");
        s1.setLongitude("77777");

        SingleBriefCase s2 = new SingleBriefCase();
        s2.setCase_id("333");
        s2.setLatitude("3333");
        s2.setLongitude("33333");

        ArrayList<SingleBriefCase> s = new ArrayList<>();
        s.add(s1);
        s.add(s2);

        return s;
    }

    @Override
    public ArrayList<CompleteCase> getUncheckedCase() {

//        String getUckd_str =
//                "{\"env\":\"cloud1-0gmugs6v938df3dc\"," +
//                "\"query\":\"db.collection(\\\"Necessary\\\").aggregate()" +
//                        ".lookup({" +
//                            "from:\\\"Unnecessary\\\"," +
//                            "localField:'case_id'," +
//                            "foreignField:'case_id'," +
//                            "as:'uncsry'}).match({checked:0}).end()\"}";

//        String getUckd_str = "{\"env\":\"cloud1-0gmugs6v938df3dc\"," +
//                "\"name\": \"getUncheckedCase\"," +
//                "\"POSTBODY\": \"123\"}";
//        JSONArray jsonArray = DataBaseUtil.actionFunc(getUckd_str).getJSONArray("data");

//        System.out.println(jsonArray);

        ArrayList<CompleteCase> clist = new ArrayList<>();
        for (int i=0;i<4;i++){
            CompleteCase completeCase = new CompleteCase();
            completeCase.setCase_id("#12346"+i);
            clist.add(completeCase);
        }

        return clist;
    }

    @Override
    public CompleteCase getCaseById(String case_id) {
        return null;
    }
}
